package com.loong.order.controller.forehead;

import com.loong.common.mvc.BaseForeheadController;
import com.loong.common.param.BaseIdParam;
import com.loong.common.rest.Result;
import com.loong.common.validator.group.CommonValidate;
import com.loong.global.dto.UserDTO;
import com.loong.order.handler.PaymentHandler;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description: 订单支付
 * @Author: hzp
 * @Date: 2021-1-11 10:09
 */
@RestController
@RequestMapping("forehead/order/payment")
public class PaymentController extends BaseForeheadController {
    @Resource
    private PaymentHandler paymentHandler;


    /**
     * 货到付款：
     *      单笔订单应付金额不能大于500
     *      累计未完成订单数量不能大于5笔
     *      累计未完成订单金额不能大于1000
     *      支持店铺分类包括：早餐  美食   夜宵
     *      条件都满足 更新订单状态为 待支付 配送中 OrderStatus WAITING_PAYMENT_AND_IN_DELIVERY(3,"待支付，配送中");
     * @param param 订单id
     *
     * @return  是否支付成功
     */
    @PostMapping("cashOnDelivery")
    public Result cashOnDelivery(@RequestBody @Validated(value = {CommonValidate.class})BaseIdParam param){
        UserDTO userDTO = getUserDTO();
        return handlerExecutor.execute(()->paymentHandler.cashOnDelivery(userDTO.getId(),param.getId()));
    }

    /**
     * 检查是否可以货到付款
     * @param param
     * @return
     */
    @PostMapping("checkCashOnDelivery")
    public Result checkCashOnDelivery(@RequestBody @Validated(value = {CommonValidate.class})BaseIdParam param){
        UserDTO userDTO = getUserDTO();
        return handlerExecutor.execute(()->paymentHandler.checkCashOnDelivery(userDTO.getId(),param.getId()));
    }
}
